package com.example.a2306_fx

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners

/**
 * 图片请求工具类
 */
object GlideUtils {
    //合适缓存策略
    fun loadImage(context: Context,url:String,imageView: ImageView){
        Glide.with(context)
            .load(url)
            .error(R.drawable.ic_launcher_foreground)
            .placeholder(R.drawable.ic_launcher_foreground)
            .skipMemoryCache(false)
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            .into(imageView)
    }
    //关闭磁盘缓存
    fun loadCircle(context: Context,url:String,imageView: ImageView){
        Glide.with(context)
            .load(url)
            .error(R.drawable.ic_launcher_foreground)
            .placeholder(R.drawable.ic_launcher_foreground)
            .skipMemoryCache(true)
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .circleCrop()
            .into(imageView)
    }
    fun loadCorner(context: Context,url:String,imageView: ImageView,radius:Int){
        Glide.with(context)
            .load(url)
            .error(R.drawable.ic_launcher_foreground)
            .placeholder(R.drawable.ic_launcher_foreground)
            .skipMemoryCache(false)
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            .transform(CenterCrop(),RoundedCorners(radius))
            .into(imageView)
    }
}